<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<!DOCTYPE html>
<html>
<head>
<jsp:include page="../../inc.jsp"></jsp:include>
<meta http-equiv="X-UA-Compatible" content="edge">
<c:if test="${fn:contains(sessionInfo.resourceList,'/expert/detailPage') }">
	<script type="text/javascript">
		$.canDetail=true;
	</script>
</c:if>
<c:if test="${fn:contains(sessionInfo.resourceList,'/expert/delete')}">
	<script type="text/javascript">
		$.canDelete=true;
	</script>
</c:if>
<title>专家数据管理</title>
	<script type="text/javascript">
	var dataGrid;
	$(function(){
		dataGrid=$('#dataGrid').datagrid({
			url:'${ctx}'+'/expert/dataGrid',
			striped:true,
			rownumbers:false,
			pagination:true,
			singleSelect:false,
			idField:'id',
			sortName:'id',
			sortOrder:'asc',
			pageSize:50,
			pageList:[10,20,30,40,50,100,200,300,400,500],
			frozenColumns:[[{
				width:'30',
				field:'ck',
				checkbox:true
			},{
				width:'150',
				title:'专家姓名',
				field:'name',
				sortable:true
				
			},{
				width:'150',
				title:'联系电话',
				field:'tel',
			},{
				width:'150',
				title:'用户密码',
				field:'password'
			},
			
			{
				width:'150',
				title:'工作单位',
				field:'department'
			},{
				field:'action',
				title:'操作',
				width:'120',
				formatter:function(value,row,index){
					var str='&nbsp;';
					if($.canDetail){
						str += $.formatString('<a href="javascript:void(0)" onclick="detailFun(\'{0}\');" >详情</a>', row.id);
					}
					str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
					if($.canDelete){
						str += $.formatString('<a href="javascript:void(0)" onclick="deleteFun({0});" >删除</a>', row.id);
					}
					return str;
				}
			}
			
			]],
			toolbar:'#toolbar'
			
		});
	});
	
	function deleteFun(id) {
		var ids = [];
		if (id == undefined) {
			var rows = dataGrid.datagrid('getSelections');
			if (rows.length == 0) {
				parent.$.messager.alert("提示", "请选择要删除的行！", "info");
				return;
			} else {
				for (i = 0; i < rows.length; ++i) {
					ids.push(rows[i].id);
				}
			}
		} else {
			dataGrid.datagrid('unselectAll').datagrid('uncheckAll');
			ids.push(id);
		}
		var jsonIds = JSON.stringify(ids);
		parent.$.messager.confirm('询问', '您是否要删除当前选中的数据？', function(b) {
			if (b) {
				progressLoad();
				$.post('${ctx}/expert/delete', {
					ids : jsonIds
				}, function(result) {
					if (result.success) {
						dataGrid.datagrid('clearSelections');
						parent.$.messager.alert('提示', result.msg, 'info');
						dataGrid.datagrid('reload')
					}
					progressClose();

				}, 'JSON');
			}
		});
	}
	function detailFun(id) {
		if (id == undefined) {
			var row = dataGrid.datagrid('getSelections');
			id = rows[0].id;
		} else {
			dataGrid.datagrid('unselectAll').datagrid('uncheckAll');
		}
		parent.$.modalDialog({
			title : '详情',
			width : 500,
			height : 400,
			href : '${ctx}/expert/detailPage?id=' + id
		});
	}
	
	</script>
</head>
<body class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'center',fit:true,border:false">
		<table id="dataGrid" data-options="fit:true,border:false"></table>
	</div>
	<div id="toolbar" style="display:none;">
		<c:if test="${fn:contains(sessionInfo.resourceList,'/expert/delete') }">
			<a onclick="deleteFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon_del'">删除</a>
		</c:if>
	</div>

</body>
</html>